package com.ruoyi.project.express.order.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.express.order.domain.ExpressOrder;
import com.ruoyi.project.express.order.service.IExpressOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 物流单号Controller
 * 
 * @author lindor
 * @date 2020-04-07
 */
@Controller
@RequestMapping("/express/order")
public class ExpressOrderController extends BaseController
{
    private String prefix = "express/order";

    @Autowired
    private IExpressOrderService expressOrderService;

    @RequiresPermissions("express:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询物流单号列表
     */
    @RequiresPermissions("express:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExpressOrder expressOrder)
    {
        startPage();
        List<ExpressOrder> list = expressOrderService.selectExpressOrderList(expressOrder);
        return getDataTable(list);
    }

    /**
     * 导出物流单号列表
     */
    @RequiresPermissions("express:order:export")
    @Log(title = "物流单号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExpressOrder expressOrder)
    {
        List<ExpressOrder> list = expressOrderService.selectExpressOrderList(expressOrder);
        ExcelUtil<ExpressOrder> util = new ExcelUtil<ExpressOrder>(ExpressOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增物流单号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物流单号
     */
    @RequiresPermissions("express:order:add")
    @Log(title = "物流单号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExpressOrder expressOrder)
    {
        return toAjax(expressOrderService.insertExpressOrder(expressOrder));
    }

    /**
     * 修改物流单号
     */
    @GetMapping("/edit/{orderId}")
    public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
    {
        ExpressOrder expressOrder = expressOrderService.selectExpressOrderById(orderId);
        mmap.put("expressOrder", expressOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存物流单号
     */
    @RequiresPermissions("express:order:edit")
    @Log(title = "物流单号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExpressOrder expressOrder)
    {
        return toAjax(expressOrderService.updateExpressOrder(expressOrder));
    }

    /**
     * 删除物流单号
     */
    @RequiresPermissions("express:order:remove")
    @Log(title = "物流单号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(expressOrderService.deleteExpressOrderByIds(ids));
    }
}
